// pages/AtsDataShow/AtsDataShow.js
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ren:[],
    chooseSize: false,
    animationData: {},
    showShopPopups: true,
    objectArray:[],
    zhuangtai:false,
    page:1,
    limit:10,
    context:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.login();
    this.selectAhther();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  showModal(e) {
    wx.showLoading({
      title: '加载中',
    })
    const that = this;
    console.log(e);
    wx.request({

      url: app.globalData.url +'AtsDataShowController/weixinselectAtsDataComparison',

      
      data: {
        athleteId: e.currentTarget.dataset.text
      },
      success: ress => {
        wx.hideLoading();
        console.info(ress.data[0])
        if (ress.data[0].length==0){
          wx.showToast({
            title: '没有数据了',
            icon: 'none',
            duration: 2000
          })
         
          return
        }
        
        that.setData({
          objectArray: ress.data,
          zhuangtai:true
        })
       
      }
    })
 
    // 显示遮罩层
    
     
  },
  sureCallBack_02(re){
   
    wx.showLoading({
      title: '加载中',
    })

  this.setData({
    zhuangtai:false
    })
    //console.info(re.detail.choosedData[0])

    wx.navigateTo({
      url: '../AtsDataBactihShow/AtsDataBactihShow?id=' + re.detail.choosedData[0].batchId + '&name=' + re.detail.choosedData[0].athleteName
    })
    wx.hideLoading()
  },
  cancleCallBack_02() {
    this.setData({
      zhuangtai: false
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
   blur: function (e) {
    this.setData({
      context: e.detail.value,
      ren: [],
      page: 1
    })
    console.info(e)
     this.selectAhther();
  },
  /**
   * 显示更多函数
   */
  next: function (e) {
    this.setData({
      page: this.data.page + 1
    })
    this.selectAhther();
  }
  ,selectAhther:function(){
    wx.showLoading({
      title: '加载中',
    })
    const that = this;
    let user = wx.getStorageSync('user');
    console.log(user.data.filId)
    if (user.data.manCardid == "superman" || user.data.filId) {
    wx.request({

      url: app.globalData.url + 'weixinController/selectAthleteAll',


      data: {
        coachId: user.data.filId,
        type: user.data.companyNum,
        page: that.data.page,
        limit: that.data.limit,
        athleteName: that.data.context
        // coachId:72
      },
      success: ress => {
        
        wx.hideLoading()
        if (ress.data.length == 0) {
          wx.showToast({
            title: '没有数据了',
            icon: 'none',
            duration: 2000
          })


          return;
        }
        console.log(ress.data)
        var arr = that.data.ren;

        for (var i = 0; i < ress.data.length; i++) {
          arr.push(ress.data[i])
        }
        that.setData({
          ren: arr,

        })

       
      }
    })
    }
    wx.hideLoading()
  }
})